--------------------------------------------------
--Vup杀卡牌包
--------------------------------------------------

--狂野模式开关
--记得把zzsystem.lua里的也设置为true
wild_mode = false --狂野模式！！（仅限服务器用，解放偷梁换柱、猴子）

--------------------------------------------------
--描述里的加号都给老子别用全角！！！——Notify
--（旧Vup杀）转换技描述里带半角加号会转不动。
--------------------------------------------------

local extension = Package:new("vupslash_cards", Package.CardPack)
extension.metadata = require "packages.vupslash_cards.metadata"
-- 加载本包的翻译包(load translations of this package)，这一步在本文档的最后进行。

--------------------------------------------------
--combobox大全
--------------------------------------------------

local basic = {
  "slash", "peach", "analeptic",
  "fire__slash", "thunder__slash", "v_ice__slash"
}
local normal_tricks = {
  "dismantlement", "snatch", "duel", "collateral",
  "ex_nihilo", "savage_assault", "archery_attack", "god_salvation",
  "amazing_grace", "iron_chain", "fire_attack",
}
local not_damage_tricks = {
  "dismantlement", "snatch", "collateral",
  "ex_nihilo", "god_salvation",
  "amazing_grace", "iron_chain",
}
local damage_tricks = {
  "duel", "fire_attack", "savage_assault", "archery_attack",
}
local suits = {
  "spade", "heart", "club", "diamond"
}

--------------------------------------------------
--检查是否存在对应阶段
--------------------------------------------------

local function exist_or_not(player, Phase)
  local exist_truth = true
  if player.skipped_phases ~= {} then
    for k in ipairs(player.skipped_phases) do
      if k == Phase then
        exist_truth = false
      end
    end
  end
  return exist_truth
end

--------------------------------------------------
--检查是否不能使用、打出或弃置某种牌
--------------------------------------------------

local function is_jilei(player, card)
  local is_jilei_or_not = false
  if player:prohibitUse(card) or player:prohibitDiscard(card) or player:prohibitResponse(card) then
    is_jilei_or_not = true
  end
  return is_jilei_or_not
end

--------------------------------------------------
--花色相对
--------------------------------------------------

local function suit_close(s)
  if s == Card.Spade then
    return Card.Club
  elseif s == Card.Club then
    return Card.Spade
  elseif s == Card.Heart then
    return Card.Diamond
  elseif s == Card.Diamond then
    return Card.Heart
  end
end

--------------------------------------------------
--返回花色字段对应的数字
--------------------------------------------------

local function suit_number(s)
  if s == "club" then
    return Card.Club
  elseif s == "spade" then
    return Card.Spade
  elseif s == "diamond" then
    return Card.Diamond
  elseif s == "heart" then
    return Card.Heart
  end
end

--------------------------------------------------
--返回phase对应的字符串
--请注意8 notactive、9 phasenone暂无官方叫法，暂未写入
--------------------------------------------------

local function phase_string(phase_int)
  if phase_int == 1 then
    return "回合开始"
  elseif phase_int == 2 then
    return "准备"
  elseif phase_int == 3 then
    return "判定"
  elseif phase_int == 4 then
    return "摸牌"
  elseif phase_int == 5 then
    return "出牌"
  elseif phase_int == 6 then
    return "弃牌"
  elseif phase_int == 7 then
    return "结束"
  else
    return "我也不知道"
  end
end

local slash = Fk:cloneCard("slash")

--------------------------------------------------
--冰杀
--------------------------------------------------

local v_iceSlashSkill = fk.CreateActiveSkill{
  name = "v_ice__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from

    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      -- damage = 1 + (effect.additionalDamage or 0),
      damage = 1,
      damageType = fk.IceDamage,
      skillName = self.name
    })
  end
}
local v_iceSlash = fk.CreateBasicCard{
  name = "v_ice__slash",
  skill = v_iceSlashSkill,
  is_damage_card = true,
}

extension:addCards{
  v_iceSlash:clone(Card.Club, 7),
  v_iceSlash:clone(Card.Club, 8),
}

--------------------------------------------------
--衍生牌：魔法剑
--------------------------------------------------

local v_magicsword_filter = fk.CreateFilterSkill{
  name = "#v_magicsword_filter",
  card_filter = function(self, card, player)
    if type(player:getMark("#v_magicsword_skill")) == "table" then
      return card.id == player:getMark("#v_magicsword_skill")[1]
    end
  end,
  view_as = function(self, card, player)
    if type(player:getMark("#v_magicsword_skill")) == "table" then
      local su = suit_number(player:getMark("#v_magicsword_skill")[2])    
      return Fk:cloneCard(card.name, su, card.number)
    end
  end,
}
local v_magicswordSkill = fk.CreateTriggerSkill{
  name = "#v_magicsword_skill",
  anim_type = "control",
  frequency = Skill.Compulsory, --如果这个会覆盖on_cost则删除
  events = {fk.AskForRetrial},
  --触发条件：（已完成）
  -- 遍历到的角色具有武器
  -- 遍历到的角色的武器class_name为魔法剑
  -- 本回合只使用过一次本技能
  -- （待补充）遍历到的角色可以使用武器
  can_trigger = function(self, event, target, player, data)
    local weapon1 = player:getEquipment(Card.SubtypeWeapon)
    return weapon1
      -- and Fk:getCardById(weapon1).class_name == "v_Magicsword" --待定
      and Fk:getCardById(weapon1).name == "v_magicsword" --待定
      and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  --使用询问：
  --改编一下prompt正常询问即可。
  on_cost = function(self, event, target, player, data)
    local room = player.room
    --确认是否发动技能。
    local prompt = "v_magicsword_choice:"..target.id.."::"..data.reason
    if room:askForSkillInvoke(player, self.name, data, prompt) then
      return true
    end
  end,
  --使用流程：
  --先提供选择，然后将花色和牌作为标记，判定结束后解除。
  --提供额外的filter技能在判定期间将魔法剑视为其他花色
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target ~= player then
      --doindicate的两个参数一个为integer，一个为table
      room:doIndicate(player.id, { target.id })
    end
    local prompt = "v_magicsword_change"
    local choice = room:askForChoice(player, suits, self.name, prompt)
    local card_id = player:getEquipment(Card.SubtypeWeapon)
    local card = Fk:getCardById(card_id)
    room:setPlayerMark(target, self.name, {card_id, choice})
    room:retrial(card, player, data, self.name, false)
  end,

  refresh_events = {fk.FinishJudge},
  can_refresh = function(self, event, target, player, data)
    return player:getMark(self.name) ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, self.name, 0)
  end,
}
v_magicswordSkill:addRelatedSkill(v_magicsword_filter)

Fk:addSkill(v_magicswordSkill)

local v_magicsword = fk.CreateWeapon{
  name = "&v_magicsword",
  -- class_name = "v_Magicsword", --待定
  -- suit = Card.Heart,
  -- number = 3,
  attack_range = 2,
  equip_skill = v_magicswordSkill,
}

extension:addCards{
  v_magicsword:clone(Card.Heart, 3),
}
-- extension:addCards(v_magicsword)


-- 加载本包的翻译包(load translations of this package)，这一步在本文档的最后进行。
dofile "packages/vupslash_cards/i18n/init.lua"

return { extension } 